package com.ruoyi.st.controller;

import java.text.ParseException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.response.JsonResult;
import com.ruoyi.st.domain.query.PerfDetailDateQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.st.domain.StPerfDetail;
import com.ruoyi.st.service.IStPerfDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 演出详情Controller
 * 
 * @author ruoyi
 * @date 2024-11-14
 */
@Slf4j
@RestController
@RequestMapping("/st/perfDetail")
public class StPerfDetailController extends BaseController
{
    @Autowired
    private IStPerfDetailService stPerfDetailService;

    /**
     * 查询演出详情列表
     */
//    @PreAuthorize("@ss.hasPermi('st:perfDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(StPerfDetail stPerfDetail)
    {
        startPage();
        List<StPerfDetail> list = stPerfDetailService.selectStPerfDetailList(stPerfDetail);
        return getDataTable(list);
    }

    //查询演出列表升序排列
    @GetMapping("/listAsc")
    public TableDataInfo selectListAsc(StPerfDetail stPerfDetail)
    {
        startPage();
        List<StPerfDetail> list = stPerfDetailService.selectStPerfDetailListAsc(stPerfDetail);
        return getDataTable(list);
    }

    /**
     * 查询演出列表降序排列
     * @param stPerfDetail
     * @return
     */
    @GetMapping("/listDesc")
    public TableDataInfo selectListDesc(StPerfDetail stPerfDetail)
    {
        startPage();
        List<StPerfDetail> list = stPerfDetailService.selectStPerfDetailListDesc(stPerfDetail);
        return getDataTable(list);
    }

    /**
     * 通过日期范围获取演出列表
     */
//    @GetMapping("/listByPerfDate/{perfStartTime}/{perfEndTime}")
//    public List<StPerfDetail> selectListByPerfDate(@PathVariable("perfStartTime") String perfStartTime,
//                                                   @PathVariable("perfEndTime") String perfEndTime) {
//        log.info("开始时间:",perfStartTime,"结束时间:",perfEndTime);
//        return stPerfDetailService.selectListByPerfDate(perfStartTime,perfEndTime);
//    }

    @PostMapping("/listByPerfDate")
    public JsonResult selectListByPerfDate(@RequestBody PerfDetailDateQuery perfDetailDateQuery)  {
        log.debug("日期查询:perfDetailDateQuery={}",perfDetailDateQuery);
         List<StPerfDetail> stPerfDetail = stPerfDetailService.selectListByPerfDate(perfDetailDateQuery);
        return JsonResult.ok(stPerfDetail);
    }


    /**
     * 导出演出详情列表
     */
    @PreAuthorize("@ss.hasPermi('st:perfDetail:export')")
    @Log(title = "演出详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StPerfDetail stPerfDetail)
    {
        List<StPerfDetail> list = stPerfDetailService.selectStPerfDetailList(stPerfDetail);
        ExcelUtil<StPerfDetail> util = new ExcelUtil<StPerfDetail>(StPerfDetail.class);
        util.exportExcel(response, list, "演出详情数据");
    }

    /**
     * 获取演出详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('st:perfDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stPerfDetailService.selectStPerfDetailById(id));
    }

    /**
     * 新增演出详情
     */
    @PreAuthorize("@ss.hasPermi('st:perfDetail:add')")
    @Log(title = "演出详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StPerfDetail stPerfDetail)
    {
        return toAjax(stPerfDetailService.insertStPerfDetail(stPerfDetail));
    }

    /**
     * 修改演出详情
     */
    @PreAuthorize("@ss.hasPermi('st:perfDetail:edit')")
    @Log(title = "演出详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StPerfDetail stPerfDetail)
    {
        return toAjax(stPerfDetailService.updateStPerfDetail(stPerfDetail));
    }

    /**
     * 删除演出详情
     */
    @PreAuthorize("@ss.hasPermi('st:perfDetail:remove')")
    @Log(title = "演出详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stPerfDetailService.deleteStPerfDetailByIds(ids));
    }
}
